<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>百商汇</title>
	<meta name="viewport" content="initial-scale = 1.0,maximum-scale = 1.0,minimum-scale = 1.0,user-scalable = no,width = device-width">
	<meta name="format-detection" content="telephone=no" />
	<link rel="stylesheet" type="text/css" href="../csses/giving.css">
</head>
<body>
	<div class="giving_title">
		赠送
		<img src="../image/back.png" onclick="goBack()">
	</div>
	<div class="giving_box">
		<ul>
			<li class="telNum">
				<span>受 &nbsp;赠 &nbsp;人</span>
				<input type="text" placeholder="请输入对方的手机号"></input>
			</li>
			<li class="amount">
				<span>金 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 额</span>
				<input type="text" placeholder="请输入您要赠送的商币金额"></input>
			</li>
			<li class="payPsw">
				<span>支付密码</span>
				<input type="password" placeholder="请输入百商汇支付密码"></input>
				<div class="choose">
					<img src="../image/psw.png">
				</div>
			</li>
			<li class="remarks">
				<span>备 &nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 注</span>
				<input type="text" placeholder="请输入备注"></input>
			</li>
		</ul>
		<button class="submitBtn">确认</button>
		<div class="remindBox">请输入正确的手机号</div>
	</div>

	<script type="text/javascript" src="../lib/flexible.js"></script>
	<script type="text/javascript" src="../lib/jquery-1.10.1.min.js"></script>
	<script type="text/javascript">
		function goBack(){
			window.history.back();
		}

		$('input').focus(function(){
			this.select();
		});

		$('.submitBtn').click(function(){
			var $toMobile = $('.telNum input').val();
			var $cloudMoney = $('.amount input').val();
			var $payPassword = $('.payPsw input').val();
			var $remindBox = $('.remindBox');
			var cloudMoneyReg = /^[0-9]|[.]$/;

			if(!(/^1[3|4|5|7|8]\d{9}$/.test($toMobile))){
				$remindBox.css('display','block');
				$remindBox.text('请输入正确的手机号');
				setTimeout(function(){
					$remindBox.css('display','none');
				},1500);
			}else if(!(/^[0-9]|[.]$/.test($cloudMoney))){
				$remindBox.css('display','block');
				$remindBox.text('请输入正确的金额');
				setTimeout(function(){
					$remindBox.css('display','none');
				},1500);
			}

			$.ajax({
				type : 'POST',
				url : "/api/v1/cloud/sendCloudMoney",
				data : {
					paramStr: "{'userName':'" + sessionStorage.userName + "','token':'" + sessionStorage.token + "','toMobile':'" + $toMobile + "','cloudMoney':'" + $cloudMoney + "','payPassword':'" + $payPassword + "'}"
				},
				dataType : "json",
				timeout : 10000,
				success : function (data) {
					if(data.code == 200){
						$('.submitBtn').attr('disabled',true).css('background','#ccc');
						setTimeout(function(){
							window.location.href = '../index1.html#!/personal';
						},1500);
					}
					$remindBox.css('display','block').text(data.message);
					setTimeout(function(){
						$remindBox.css('display','none');
					},1500);
				},
				error : function (xhr,type,errorThrown){
					// alert('未知错误');
				}
			});
		});

		// $.ajax({
		// 	type : 'post',
		// 	url : '/api/v1/agreement/about',
		// 	success : function (data) {
		// 		console.log(data);
		// 	}
		// });
	</script>
</body>
</html>